/**
 * Copyright (C) 2018-2022
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制
 */
package co.yixiang.controller.manager.system;

import co.yixiang.common.annotation.ForbidSubmit;
import co.yixiang.common.annotation.Log;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.modules.system.entity.dto.AgentHierarchyQueryCriteria;
import co.yixiang.modules.system.entity.dto.MenuQueryCriteria;
import co.yixiang.modules.system.service.AgentHierarchyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author hupeng
 * @date 2018-12-03
 */
@Api(tags = "系统：菜单管理")
@RestController
@RequestMapping("/api/agentHierarchy")
@SuppressWarnings("unchecked")
public class AgentHierarchyController {

    private final AgentHierarchyService agentHierarchyService;

    private final IGenerator generator;

    private static final String ENTITY_NAME = "agentHierarchy";

    public AgentHierarchyController(AgentHierarchyService agentHierarchyService, IGenerator generator) {
        this.agentHierarchyService = agentHierarchyService;
        this.generator = generator;
    }

    @ForbidSubmit
    @Log("导出菜单数据")
    @ApiOperation("导出菜单数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('menu:list')")
    public void download(HttpServletResponse response, MenuQueryCriteria criteria) throws IOException {

        // agentHierarchyService.download(generator.convert(agentHierarchyService.queryAll(criteria), MenuDto.class), response);
    }
    @ApiOperation(value = "查询")
    @GetMapping(value = "/")
    public ResponseEntity getYxArticles(AgentHierarchyQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity(agentHierarchyService.queryAll(criteria, pageable), HttpStatus.OK);
    }


    @ApiOperation(value = "查询")
    @GetMapping(value = "/list")
    public ResponseEntity getYxArticlesList(AgentHierarchyQueryCriteria criteria) {
        return new ResponseEntity(agentHierarchyService.queryAll(criteria), HttpStatus.OK);
    }
}
